<template>
  <div class="">
    <el-row>
      <el-col :span="24"
        ><div class="grid-content bg-purple-dark">
          <span
            style="
              margin-left: -88%;
              font-size: 30px;
              font-family: '宋体';
              font-weight: bold;
            "
            >报修回访</span
          >
          <el-breadcrumb
            style="margin-left: 20px; margin-top: 8px"
            separator="/"
          >
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>报修管理</el-breadcrumb-item>
            <el-breadcrumb-item>报修回访</el-breadcrumb-item>
          </el-breadcrumb>
        </div></el-col
      >
    </el-row>

    <el-row height="20px">
      <el-col :span="24"
        ><div
          class="grid-content bg-purple-dark"
          style="
            margin-left: -90%;
            font-size: 20px;
            font-weight: bold;
            color: gray;
          "
        >
          查询条件
        </div></el-col
      >
      <el-col :span="5"
        ><div class="grid-content bg-purple" style="margin-left: 20px">
          <el-input
            placeholder="请输入工单ID"
            v-model="pageDto.workId"
          ></el-input></div
      ></el-col>
      <el-col :span="5"
        ><div class="grid-content bg-purple" style="margin-left: 20px">
          <el-input
            placeholder="请输入报修人"
            v-model="pageDto.name"
          ></el-input></div
      ></el-col>
      <el-col :span="5"
        ><div class="grid-content bg-purple" style="margin-left: 20px">
          <el-input
            placeholder="请输入联系电话"
            v-model="pageDto.phone"
          ></el-input></div
      ></el-col>

      <el-col :span="5"
        ><div class="grid-content bg-purple" style="margin-left: 20px">
          <el-select v-model="pageDto.status" placeholder="请选择报修状态">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
      </el-col>

      <el-col :span="4">
        <div
          class="grid-content bg-purple"
          style="text-align: right; margin-right: 10px"
        >
          <el-button
            type="success"
            icon="el-icon-search"
            size="small"
            @click="findPage()"
            >查询</el-button
          >
          <el-button
            type="primary"
            icon="el-icon-refresh-left"
            size="small"
            @click="resetForm()"
            >重置</el-button
          >
        </div>
      </el-col>
    </el-row>

    <el-dialog
      title="回访"
      :visible.sync="dialog"
      width="30%"
      :close-on-click-modal="false"
      center
      :append-to-body="true"
    >
      <el-row>
        <el-col :span="5"
          ><div class="grid-content bg-purple">回访内容</div></el-col
        >
        <el-col :span="19"
          ><div class="grid-content bg-purple-light">
            <el-input
              type="textarea"
              :rows="3"
              placeholder="请输入内容"
              v-model="repReg.visitContent"
            >
            </el-input></div></el-col
        ><span slot="footer" class="dialog-footer">
          <el-button @click="dialog = false">取 消</el-button>
          <el-button type="primary" @click="updReg">确 定</el-button>
        </span>
      </el-row>
    </el-dialog>

    <el-row>
      <el-col :span="24"
        ><div
          class="grid-content bg-purple"
          style="text-align: left; margin-left: 20px; font-weight: bold"
        >
          报修回访
        </div>
      </el-col>
      <el-table :data="pagination.records" style="width: 100%">
        <el-table-column prop="workId" label="工单ID" align="center">
        </el-table-column>
        <el-table-column prop="repAdr" label="位置" align="center">
        </el-table-column>
        <el-table-column
          prop="repForm.fromName"
          label="报修内容"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="name" label="报修人" align="center">
        </el-table-column>
        <el-table-column prop="phone" label="联系电话" align="center">
        </el-table-column>
        <el-table-column prop="repTime" label="维修时间" align="center">
        </el-table-column>
        <el-table-column
          prop="workStatu"
          label="状态"
          align="center"
        ></el-table-column>
        <el-table-column
          fixed="right"
          label="操作"
          width="300px"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              v-if="scope.row.workStatu == '未回访'"
              @click="updRegUI(scope.row)"
              >回访</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination
        @current-change="findPage"
        :current-page="pagination.current"
        :page-sizes="[1, 5, 10, 15, 20]"
        :page-size="pagination.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="pagination.total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      pagination: [],
      dialog: false,
      updDialog: false,
      pageDto: {
        pageNum: 1,
        pageSize: 10,
        workId: null,
        name: null,
        phone: null,
        status: "未回访",
      },
      maintains: [],

      options: [
        { value: "未回访", label: "未回访" },
        { value: "已回访", label: "已回访" },
      ],
      repReg: {
        workId: "",
        formId: "",
        name: "",
        phone: "",
        repAdr: "",
        maintain: "",
        repTime: "",
        workStatu: "",
        visitContent: null,
        adminId: null,
        addtime: "",
      },
    };
  },
  components: {},
  methods: {
    //重置搜索条件
    resetForm() {
      this.pageDto.pageNum = 1;
      this.pageDto.pageSize = 10;
      this.pageDto.workId = null;
      this.pageDto.phone = null;
      this.pageDto.name = null;
      this.pageDto.status = "未回访";
      this.findPage();
      // this.$refs[name].resetFields();
    },
    //关闭时清空repReg对象的值
    clear() {
      this.repReg = {};
    },
    //分页信息显示
    findPage() {
      console.log(this.pageDto);
      this.$axios
        .post("/leanyuan/rep-reg/findReg", this.pageDto)
        .then((resp) => {
          this.pagination = resp.data.data;
          console.log(resp.data);
        })
        .catch((ex) => {});
    },

    //打开修改界面
    updRegUI(row) {
      console.log(row);
      this.dialog = true;
      this.repReg = row;
    },

    //修改
    updReg() {
      this.repReg.workStatu = "已回访";
      this.$axios
        .post("/leanyuan/rep-reg/updReg", this.repReg)
        .then((resp) => {
          if (resp.data.status == "200") {
            //确认后跳转到详情页
            console.log(resp);
            this.$alert("修改成功!", "提示", {
              confirmButtonText: "确定",
              callback: (action) => {
                this.dialog = false;
              },
            });
          } else {
            this.$alert("修改失败!");
          }
          this.findPage();
          this.dialog = false;
        })
        .catch((ex) => {});
    },
  },
  mounted() {
    this.findPage();
  },
};
</script>

<style  scoped>
.el-row {
  margin-bottom: 20px;
}
.el-col {
  border-radius: 4px;
  background-color: white;
  height: 80px;
}
.el-cascader {
  width: 100%;
}
.grid-content {
  border-radius: 4px;
  min-height: px;
}
.row-bg {
  padding: 10px 0;
}
</style>
